<style>
    .operator-mg{
        background:#FFFEE6;
        color:#8F5700;
        padding:12px;
    }
    .operator-mg-tip{
        width:16px;
        height:16px;
        margin-right:8px;
        float:left;
    }
    #search{

    }
</style>
<script type="text/javascript">
    function visitorLogSearch() {
        $('#log-list').datagrid('load', {
            ip: $('#ip').val(),
            time: $('#time').datetimebox('getValue'),
            time1: $('#time1').datetimebox('getValue'),
            time2: $('#time2').datetimebox('getValue'),
            webId: $('#webId').val(),
            serviceId: $('#serviceId').val()
        });
    }
    function visitorDownload() {
        $('#visitor-chat-download-ip').val($('#ip').val());
        $('#visitor-chat-download-time').val($('#time').datetimebox('getValue'));
        $('#visitor-chat-download-time1').val($('#time1').datetimebox('getValue'));
        $('#visitor-chat-download-time2').val($('#time2').datetimebox('getValue'));
        $('#visitor-chat-download-webId').val($('#webId').val());
        $('#visitor-chat-download-serviceId').val($('#serviceId').val());
        $('#visitor-chat-download').form('submit', {
            url: "<?php echo $this->config->item('base_url'); ?>visitor/download",
        });
    }

    //添加右击菜单内容
    function onRowMenuVisitorChat(e, rowIndex, rowData) {
        e.preventDefault();
        var selected = $("#log-list").datagrid('getRows'); //获取所有行集合对象
        selected[rowIndex].id; //index为当前右键行的索引，指向当前行对象
        $('#visitor-chat-dlg_menu').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    }
    function visitorChatSaveFileDialog() {
        if ($("#log-list").datagrid('getSelected')) {
            $('#visitor-chat-dlg').dialog('open').dialog('setTitle', '下载记录');
        } else {
            $.messager.confirm('错误', '请左击选中条目');
        }
    }
    function visitorRowsChatDownload() {
        var downloadForm = document.forms['visitor-chat-download'];
        var rows = $("#log-list").datagrid('getSelections');
        if (rows) {
            var record = '';
            for (var i = 0; i < rows.length; i++) {
                record = record + "ID：" + rows[i].id + "\\r\\n" + "来源IP：" + rows[i].ip + "\\r\\n" + "客服ID：" + rows[i].service_id + "\\r\\n" + "聊天时间：" + rows[i].time + "\\r\\n" + "客服账号：" + rows[i].service_account + "\\r\\n" + "上传文件的路径：" + rows[i].filepath + "\\r\\n" + "web客户临时ID：" + rows[i].cid + "\\r\\n" + "客服人员临时会话ID：" + rows[i].sid + "\\r\\n" + "聊天内容：" + rows[i].content + "\\r\\n" + "\\r\\n";
            }
            $('#visitor-chat-download-record').val(record);
            downloadForm.action = "<?php echo $this->config->item('base_url'); ?>visitor/rowDownload";
            downloadForm.submit();
        } else {
            $.messager.confirm('错误', '请左击选中条目');
        }
        $('#visitor-chat-dlg').dialog('close');
    }
</script>
<div class="operator-mg">
    <div class="operator-mg-tip icon-tip"></div>
    <div>温馨提示：在列表中点击右键可以弹出操作菜单</div>
</div>
<table id="log-list" class="easyui-datagrid" 
       url="<?php echo $this->config->item('base_url'); ?>Visitor/getLogList"
       title="咨询记录" toolbar="#visitor-tb"
       rownumbers="true" pagination="true" fitColumns="true"
       data-options ="onRowContextMenu:onRowMenuVisitorChat">
    <thead>
        <tr>
            <th checkbox="true"></th>
            <th field="id" align="center" width="50">ID</th>
            <th field="ip" align="center" width="80">来源IP</th>
            <th field="cid" align="center" width="50">web客户临时ID</th>
            <th field="content" align="center" width="160">聊天内容</th>
            <th field="filepath" align="center" width="50">上传文件路径</th>
            <th field="service_id" align="center" width="50">客服ID</th>
            <th field="service_account" align="center" width="50">客服账号</th>
            <th field="sid" align="center" width="70">客服人员临时会话ID</th>
            <th field="time" align="center" width="90">聊天时间</th>
        </tr>
    </thead>
</table>
<div id="visitor-tb" style="padding:5px;height:auto">
    <div id="visitor-chat" style="margin:10px 10px 5px 5px">
        IP查询：&nbsp;<input id="ip" style="width:200px">
        时间查询：<input id="time" class="easyui-datetimebox" style="width:200px;"><br/>
        时间段查询：&nbsp;
        从&nbsp;<input id="time1" class="easyui-datetimebox"  style="width:200px;">
        &nbsp;到&nbsp;<input id="time2" class="easyui-datetimebox" style="width:200px;"><br/>
        web客户临时ID：&nbsp;<input id="webId" style="width:200px">
        客服ID：<input id="serviceId" style="width:200px">
        <button onclick="visitorLogSearch()">搜索</button>
        <input type="reset"  valuse="重置">
        <button onclick="visitorDownload()">下载</button>
    </div>
</div>
<form method="post" id="visitor-chat-download" hidden="true">
    <input id="visitor-chat-download-ip" name="ip">
    <input id="visitor-chat-download-time" name="time">
    <input id="visitor-chat-download-time1" name="time1">
    <input id="visitor-chat-download-time2" name="time2">
    <input id="visitor-chat-download-webId" name="webId">
    <input id="visitor-chat-download-serviceId" name="serviceId">
</form>
<!--右键菜单-->
<div id="visitor-chat-dlg_menu" class="easyui-menu" style="width:120px;">
    <div onClick="visitorChatSaveFileDialog()" data-options="iconCls:'icon-save'">下载</div>
    <div class="menu-sep"></div>
    <div onClick="$('#log-list').datagrid('reload');" data-options="iconCls:'icon-reload'">刷新</div>
</div>
<!--本地保存弹窗-->
<div id="visitor-chat-dlg" class="easyui-dialog" style="width:auto;height:auto;padding:10px 20px"
     closed="true" buttons="#visitor-chat-dlg-buttons">
    <span>您将下载所有被选中的记录</span>
</div>
<div id="visitor-chat-dlg-buttons">
    <a class="easyui-linkbutton" iconCls="icon-ok" onclick="visitorRowsChatDownload()">下载</a>
    <a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#visitor-chat-dlg').dialog('close')">取消</a>
</div>
